<!-- </*
 * @Author: RDSunday 
 * @Date: 2020-03-22 15:43:08 
 * @Last Modified by:   RDSunday 
 * @Last Modified time: 2020-03-22 15:43:08 
 */ -->
<!-- 菜单按钮切换打开/关闭 -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            display: inline-block;
            cursor: pointer;
        }
        .bar1, .bar2, .bar3 {
            width: 35px;
            height: 5px;
            background-color: #333;
            margin: 6px 0;
            transition: 0.4s;
        }
        .change .bar1 {
            -webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
    transform: rotate(-45deg) translate(-9px, 6px) ;
        }
        .change .bar2 {opacity: 0;}

.change .bar3 {
    -webkit-transform: rotate(45deg) translate(-8px, -8px) ;
    transform: rotate(45deg) translate(-8px, -8px) ;
}
    </style>
</head>
<body>
    <p>点击菜单按钮变为“x”</p>
    <div class="container" onclick="myFunction(this)">
        <div class="bar1"></div>
        <div class="bar2"></div>
        <div class="bar3"></div>
    </div>
    <script>
        function myFunction(x) {
            x.classList.toggle("change");
        }
    </script>
</body>
</html>